package com.nny.alarm.more;

import java.util.Calendar;

import android.content.Context;

import com.nny.alarm.R;
import com.nny.alarm.eidt.CycleEditor;
import com.uxwine.alarm.TimeCycle;
import com.uxwine.alarm.mon.AlarmContext;

public class AlarmBriefUtil
{
	Context mCtx;
	String[] mCycleStrings;
	
	public AlarmBriefUtil(Context ctx)
	{
		mCtx = ctx;
		mCycleStrings = ctx.getResources().getStringArray(R.array.alerm_cycle);
	}
	
	public String getCycleString(TimeCycle cycle)
	{
		int index = CycleEditor.getCyclePosition(cycle);
		if(index > 5)
		{
			String text = "每周：";
			for(int i = 0; i < 7; i++)
			{
				if(cycle.isSet(i))
					text += "周" + (i+1);
			}
			return text;			
		}
		return mCycleStrings[CycleEditor.getCyclePosition(cycle)];
	}
	
	public String getTitle(Calendar trigger)
	{
		return AlarmContext.formatTime(mCtx, trigger);
	}
	
	public String getDetail(TimeCycle tc, Calendar trigger)
	{
		return getTimeString(tc, trigger) + getCycleString(tc);
	}
	
	public String getTriggerDetail(TimeCycle tc, Calendar trigger)
	{
		return AlarmContext.formatYMDHM(mCtx, trigger);
	}
	
	public String getTimeString(TimeCycle tc, Calendar trigger)
	{
		if(tc.isOnce())
		{
			return AlarmContext.formatYMD(mCtx, trigger);
		}
		else if(tc.isEveryYear())
		{
			return AlarmContext.formatMD(mCtx, trigger);
		}
		else if(tc.isEveryMonth())
		{
			return AlarmContext.formatD(mCtx, trigger);
		}
		return "";
	}
}
